package com.ssc.manager.common.utils;

import com.ssc.manager.admin.entity.db.Bet;
import com.ssc.manager.admin.entity.db.Play;
import com.ssc.manager.common.constant.SystemConstant;
import com.ssc.manager.common.system.SystemData;
import com.ssc.manager.trading.dto.BetDto;

public class BetiingUtils {
	
	private static final String TYPEKEY = "_";
	
	private static final String PLAYKEY="play";
	
	/**
	 * 交易项待交易注单列表 key
	 * @param itemType
	 * @param tradeType
	 * @return
	 */
	public static String findBetKey(String itemType,String tradeType){
		return itemType+TYPEKEY+tradeType;
	}
	
	/**
	 * 汇总数据唯一key 前台展示数据列表
	 * @param gmaeCode
	 * @param palyCode
	 * @param itemCode
	 * @param trade
	 * @return
	 */
	public static String findItemKey(String gmaeCode,String palyCode,String itemCode,String trade){
		return gmaeCode+TYPEKEY+palyCode+TYPEKEY+itemCode+TYPEKEY+trade;
	}
	
	/**
	 * 交易列表key 卖单交易买单 
	 * @param itemType
	 * @param tradeType
	 * @return
	 */
	public static String findReallyBetKey(String itemType,String tradeType){
		return itemType+TYPEKEY+(SystemConstant.TRADEBUY.equals(tradeType)?SystemConstant.TRADESELL:SystemConstant.TRADEBUY);
	}
	
	/**
	 * 交易列表key 反向交易key
	 * @param contraryItemType
	 * @param tradeType
	 * @return
	 */
	public static String findContraryBetKey(String contraryItemType,String tradeType){
		return contraryItemType+TYPEKEY+tradeType;
	}
	
	/**
	 * 注单对列 分类key
	 * @param playid
	 * @return
	 */
	public static String findPlaykey(String playid){
		return playid+TYPEKEY+PLAYKEY;
	}
	
	public static String findSumItemKey(String itemCode,String tradeType){
		return itemCode+TYPEKEY+tradeType;
	}
	
	public static Bet betConvertByDto(BetDto betDto){
		Bet bet = new Bet();
		Play play  = SystemData.findPlay(String.valueOf(betDto.getPlayid()));
		bet.setOnlyCode(betDto.getOnlyCode());
		bet.setPlayId(betDto.getPlayid());
		bet.setUserId(betDto.getUserid());
		bet.setItemCode(play.getItemCode());
		bet.setItemName(play.getItemName());
		bet.setReverseCode(play.getReverseCode());
		bet.setTradeType(betDto.getTradeType());
		bet.setOrlMoney(betDto.getSumMoney());
		bet.setOdds(betDto.getOdds());
		bet.setStatus(SystemConstant.BET_BEGIN);
		return bet;
	}
	
	/*public static String findOnlyBetKey(final BetDto betDto){
		String playkey = findPlaykey(betDto.getGameCode(), betDto.getPlayCode());
		String type = findBetKey(betDto.getItemType(), betDto.getTradeType());
		return playkey+TYPEKEY+type;
	}*/
}
